/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.model.transition;

import java.util.ArrayList;
import simhya.model.store.Function;
import simhya.matheval.SymbolArray;
import simhya.model.store.Store;

/**
 *
 * @author luca
 */
public class BasicAtomicReset implements AtomicReset {

    public int variable;
    public Function resetFunction;
    public double newValue;

    BasicAtomicReset(int var, Function func) {
        this.variable = var;
        this.resetFunction = func;
    }

    public void computeNewValues() {
        newValue = resetFunction.compute();
    }

    public void computeNewValuesCache() {
        newValue = resetFunction.computeCache();
    }

    public void updateStoreVariables(double[] variables) {
        variables[variable] = newValue;
    }

    public void updateStoreVariables(SymbolArray variables) {
        variables.setValue(variable, newValue);
    }

    public double getConstantIncrement() {
        return this.resetFunction.getConstantIncrement();
    }

    public boolean isConstantIncrement() {
        return this.resetFunction.isConstantIncrementFunction();
    }

    public ArrayList<Integer> getUpdatedVariables() {
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(variable);
        return list;
    }

    public boolean isSimpleResetForVariable(int variable) {
        return (this.variable == variable);
    }

    public String toModeLanguage(Store store) {
        String f = resetFunction.toModelLanguage();
        if (f.contains("+=") || f.contains("-="))
            return f;
        return store.getVariablesReference().getName(variable) + " = " + f;
    }




    


}
